package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cennavi.buss.service.imp.ISourceService;
import com.cennavi.minemap.bean.MessageBean;

@RestController
@RequestMapping("/service/source")
public class SourceController {
	@Autowired
	private ISourceService iSourceService;
	
	@RequestMapping(method = RequestMethod.POST, value = "/update", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean update(@RequestBody String json){
		return iSourceService.update(json);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryById(@PathVariable int id){
		return iSourceService.queryById(id);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/statistic/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryStatisticById(@PathVariable int id){
		return iSourceService.queryStatisticById(id);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/list", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryById(@RequestParam("userId") int userId, @RequestParam("groupId") int groupId){
		return iSourceService.queryByUserGroupId(userId, groupId);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/tileJson/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody String queryStyle(@PathVariable int id){
		return iSourceService.queryStyle(id);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/self/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean querySelfById(@PathVariable int userId){
		return iSourceService.querySelfById(userId);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/layerDesc/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean querySourceLayerDescById(@PathVariable int id){
		return iSourceService.querySourceLayerDescById(id);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/buy", produces = "application/json;charset=UTF-8")
	public MessageBean sourceBuy(@RequestBody String json) {
		return iSourceService.sourceBuy(json);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/group/list", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryGroup(){
		return iSourceService.queryGroup();
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/group/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryGroupByUserId(@PathVariable int userId){
		return iSourceService.queryGroupByUserId(userId);
	}
	
	@RequestMapping(method = RequestMethod.GET, value = "/info/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryGroupSourceLayerBy(@PathVariable int userId){
		return iSourceService.queryGroupSourceLayerBy(userId);
	}
	
}
